import QtQuick 2.12
import QtQuick.Window 2.12

Window {
    id: window
    visible: true
    width: 768
    height: 1024
    title: qsTr("Hello World")

    property bool clickStatus: false;
    property string ambinet_temp: "0 C"
    property var temp: 0

    Rectangle {
        id: rectangle
        gradient: Gradient {
            GradientStop {
                position: 0.016
                color: "#9dfcb7"
            }

            GradientStop {
                position: 0
                color: "#9dfcf7"
            }

            GradientStop {
                position: 0.35
                color: "#9dfcf7"
            }

            GradientStop {
                position: 0
                color: "#9dfcf7"
            }

            GradientStop {
                position: 0.586
                color: "#9dfcf7"
            }

            GradientStop {
                position: 1
                color: "#000000"
            }
        }
        anchors.fill: parent

        Sender {
            id: sender
            target : receiver
            x: 100
            y: 167
            circleColor: "#504bf0"
            contentText: "Sender"
            anchors.verticalCenter: parent.verticalCenter
        }

        Receiver {
            id: receiver
            x: 480
            y: 167
            circleColor: "#f92424"
            contentText: "Receiver"
            anchors.verticalCenter: parent.verticalCenter
        }

        Image {
            id: image
            x: 8
            y: 8
            width: 100
            height: 100
            fillMode: Image.PreserveAspectFit
           // source: "icon/toggle-off-small@2x.png"
            source: clickStatus? "/icon/Toggle_On_Large.png" : "/icon/toggle-off-small@2x.png"

            MouseArea {
                            anchors.fill: parent
                            onClicked:{
                                clickStatus = !clickStatus;
                                qmlpro.setLed(clickStatus);

                                if(clickStatus==false)
                                {
                                    timer_button.running = false;
                                    console.log("timer is off")
                                }
                                else
                                {
                                   timer_button.running = true;
                                }

//                                temp++;
//                                var str = temp.toString();
//                                str += " C"
//                                ambient_temp.text = str
                            }
                      }
            }


        Image {
            id: image1
            x: 334
            y: 8
            width: 100
            height: 100
            fillMode: Image.PreserveAspectFit
            source: "icon/Icon_Health_Status_Health_Green_Heart_DBE.png"
        }

        Image {
            id: image2
            x: 646
            y: 8
            width: 100
            height: 100
            fillMode: Image.PreserveAspectFit
            source: "icon/Icon_Fan_Unselected_875.png"
        }





        TextEdit {
            id: ambient_temp
            x: 429
            y: 209
            width: 152
            height: 35
            color: "#1724e4"
            text: qsTr("Text Edit")
            font.pixelSize: 30
        }

        Timer {
                id: timer_button;
                interval: 2000;
                repeat: true
                running: true
                triggeredOnStart: false
                onTriggered: {
                    //ambient_temp.color = "red"
                    var str = qmlpro.get_temp();
                    ambient_temp.text = str

                }
            }

        Text {
            id: ambient_text
            x: 193
            y: 204
            text: qsTr("ambient temp:")
            font.pixelSize: 30
        }
    }

}
